package com.sanji.sjmallmodule.account;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.sanji.sjmallapp.BaseActivity;
import com.sanji.sjmallapp.R;
import com.sanji.sjmallmodule.main.MainActivity;
import com.sanji.sjmallwidget.XListView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * 交易明细
 */
public class BusinessDetailActivity extends BaseActivity implements View.OnClickListener, RadioGroup.OnCheckedChangeListener, XListView.IXListViewListener {
    @BindView(R.id.common_back_img)
    ImageView commonBackImg;
    @BindView(R.id.common_left_tv)
    TextView commonLeftTv;
    @BindView(R.id.common_right_img)
    ImageView commonRightImg;
    @BindView(R.id.business_radio_group)
    RadioGroup businessRadioGroup;//交易明细-0、收入-1、消费-2
    @BindView(R.id.select_time_type_group)
    RadioGroup selectTimeTypeGroup;//全部-0、本周-1、本天-2、本月-3
    @BindView(R.id.bussiness_detail_view)
    View bussinessDetailView;
    @BindView(R.id.bussiness_income_view)
    View bussinessIncomeView;
    @BindView(R.id.bussiness_consume_view)
    View bussinessConsumeView;
    @BindView(R.id.all_type_list_view)
    XListView allTypeListView;
    @BindView(R.id.today_type_list_view)
    XListView todayTypeListView;
    @BindView(R.id.week_type_list_view)
    XListView weekTypeListView;
    @BindView(R.id.month_type_list_view)
    XListView monthTypeListView;
    private String businessTypeParam = "";
    private String timeTypeParam = "";
    private BusinessDetailAdapter adapter;
    private List<BusinessDetailBean> allTypeData;
    private List<BusinessDetailBean> todayTypeData;
    private List<BusinessDetailBean> weekTypeData;
    private List<BusinessDetailBean> monthTypeData;
    private boolean orderCanLoader = false;
    private int orderIndex = 1;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_business_detail);
        ButterKnife.bind(this);
        initView();
    }

    public void initView() {
        commonLeftTv.setText(R.string.bussiness_detail);
        commonRightImg.setVisibility(View.VISIBLE);
        commonRightImg.setImageResource(R.mipmap.my_little_img);
        commonBackImg.setOnClickListener(this);
        commonRightImg.setOnClickListener(this);
        businessRadioGroup.setOnCheckedChangeListener(this);
        selectTimeTypeGroup.setOnCheckedChangeListener(this);
        allTypeListView.setPullLoadEnable(false);
        allTypeListView.setFooterDividersEnabled(false);
        allTypeListView.setHeaderDividersEnabled(false);
        allTypeListView.setXListViewListener(this);
        //
        todayTypeListView.setPullLoadEnable(false);
        todayTypeListView.setFooterDividersEnabled(false);
        todayTypeListView.setHeaderDividersEnabled(false);
        todayTypeListView.setXListViewListener(this);
        //
        weekTypeListView.setPullLoadEnable(false);
        weekTypeListView.setFooterDividersEnabled(false);
        weekTypeListView.setHeaderDividersEnabled(false);
        weekTypeListView.setXListViewListener(this);
        //
        monthTypeListView.setPullLoadEnable(false);
        monthTypeListView.setFooterDividersEnabled(false);
        monthTypeListView.setHeaderDividersEnabled(false);
        monthTypeListView.setXListViewListener(this);
        allTypeData = new ArrayList<>();
        todayTypeData = new ArrayList<>();
        weekTypeData = new ArrayList<>();
        monthTypeData = new ArrayList<>();
        ((RadioButton) businessRadioGroup.getChildAt(0)).setChecked(true);
        ((RadioButton) selectTimeTypeGroup.getChildAt(0)).setChecked(true);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.common_back_img:
                finish();
                break;
            case R.id.common_right_img:
                Intent intent = new Intent(this, MainActivity.class);
                startActivity(intent);
                break;
        }
    }

    @Override
    public void onCheckedChanged(RadioGroup radioGroup, int i) {
        switch (radioGroup.getId()) {
            case R.id.business_radio_group:
                //交易明细、收入、消费
                businessRadioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(RadioGroup radioGroup, int i) {
                        switch (i) {
                            case R.id.bussiness_detail_radio_btn:
                                //交易明细
                                businessTypeParam = "" + 0;
                                bussinessDetailView.setVisibility(View.VISIBLE);
                                bussinessIncomeView.setVisibility(View.INVISIBLE);
                                bussinessConsumeView.setVisibility(View.INVISIBLE);
                                break;
                            case R.id.bussiness_income_radio_btn:
                                //收入
                                bussinessDetailView.setVisibility(View.INVISIBLE);
                                bussinessIncomeView.setVisibility(View.VISIBLE);
                                bussinessConsumeView.setVisibility(View.INVISIBLE);
                                break;
                            case R.id.bussiness_consume_radio_btn:
                                //消费
                                bussinessDetailView.setVisibility(View.INVISIBLE);
                                bussinessIncomeView.setVisibility(View.INVISIBLE);
                                bussinessConsumeView.setVisibility(View.VISIBLE);
                                break;

                        }
                    }
                });
                break;
            case R.id.select_time_type_group:
                //周天、全部
                selectTimeTypeGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
                    @Override
                    public void onCheckedChanged(RadioGroup radioGroup, int i) {
                        switch (i) {
                            case R.id.all_type_radio_button:
                                //全部
                                allTypeListView.setVisibility(View.VISIBLE);
                                todayTypeListView.setVisibility(View.INVISIBLE);
                                weekTypeListView.setVisibility(View.INVISIBLE);
                                monthTypeListView.setVisibility(View.INVISIBLE);
                                break;
                            case R.id.today_radio_button:
                                //今天
                                allTypeListView.setVisibility(View.INVISIBLE);
                                todayTypeListView.setVisibility(View.VISIBLE);
                                weekTypeListView.setVisibility(View.INVISIBLE);
                                monthTypeListView.setVisibility(View.INVISIBLE);

                                break;
                            case R.id.week_radio_button:
                                //本周
                                allTypeListView.setVisibility(View.INVISIBLE);
                                todayTypeListView.setVisibility(View.INVISIBLE);
                                weekTypeListView.setVisibility(View.VISIBLE);
                                monthTypeListView.setVisibility(View.INVISIBLE);
                                break;
                            case R.id.month_radio_button:
                                //本月
                                allTypeListView.setVisibility(View.INVISIBLE);
                                todayTypeListView.setVisibility(View.INVISIBLE);
                                weekTypeListView.setVisibility(View.INVISIBLE);
                                monthTypeListView.setVisibility(View.VISIBLE);
                                break;
                        }
                    }
                });

                break;
        }

    }

    /***
     * 发送网络请求
     */
    public void requestData() {

    }

    @Override
    public void onRefresh() {
        if (allTypeListView.isShown()) {
            if (orderCanLoader) {
                orderIndex++;
                requestData();
            }
        } else if (todayTypeListView.isShown()) {

        } else if (weekTypeListView.isShown()) {

        } else if (monthTypeListView.isShown()) {

        }

    }

    @Override
    public void onLoadMore() {

    }
}
